<<<<<<< HEAD
 var MImage = Backbone.Model.extend({
     //CURD
     listImage: function(pagenum) {
         $.ajax({
             url: "http://survey.wrud.net/api/image/index/" + pagenum,
             type: "GET",
             dataType: "json",
             data: {
                 type: 'admin'
             },
             success: function(res) {
                 AppImage.render(res.data);
             }
         });

     }

 });

 var VImage = Backbone.View.extend({
     events: {
         "click .btn-tagadd": "addTag",
         "click .btn-tagdel": "delTag",
         "click .btn-publish": "publishImage",
         "click .btn-crawl": "crawlImage",
         "click .btn-delete": "deleteImage"
     },
     initialize: function(argument) {
         this.setElement($('body'));
         this.first = true;
     },
     render: function(data) {
         html = "";
         for (var i = 0, len = data.length; i < len; i++) {
             data[i];

             data[i].height = parseInt(data[i].height) * 196 / parseInt(data[i].width);
             data[i].width = 196;
             data[i].url = data[i].source;
             html += template.render("pinTpl", data[i]);
         };
         $("#imglist").html(html);
         /*
         $container = $("#imglist");
         var $newElems = $(html);
         $container.masonry('appended', $newElems, true);
         var $img = $(newElements).find('.showGirl').css({
             opacity: 0
         });
         var $default = $(newElements).find('.Pin_default');
         //在添加到masonry布局之前保证图片载入
         $newElems.imagesLoaded(function() {
             //现在可以显示所有的元素了
             $img.animate({
                 opacity: 1
             });
             $default.hide().remove(); 
         });
         pagenum++;
        
         if (this.first) {
             this.first = false;
             $("#imglist").masonry({
                 itemSelector: '.img'
             });
         } else {
             $("#imglist").masonry("reload");
         }*/
     },

     refresh: function(pagenum) {
         console.log(pagenum)
         this.model.listImage(pagenum);
     },

     addTag: function(e) {
         var tagname = prompt("标签", "请在这里输入");
         if (tagname != null && tagname != "") {
             var id = $(e.target).parents(".img").attr("data-id");
             console.log("你输入的是：" + tagname);
         } else {
             console.log("你什么也没有输入");
         }
     },

     delTag: function(e) {
         var id = $(e.target).parents(".img").attr("data-id");
         var tag_id = $(e.target).attr("data-id");
         console.log("delete tag");
     },

     publishImage: function(e) {
         var id = $(e.target).parents(".img").attr("data-id");
         $.ajax({
             url: "http://survey.wrud.net/api/image/publish",
             type: "POST",
             data: {
                 id: id
             },
             dataType: "json",
             success: function(res) {
                 if (0 == res.response.code) {
                     console.log("success");
                 }
             }
         });
     },

     deleteImage: function(e) {
         var id = $(e.target).parents(".img").attr("data-id");
         $.ajax({
             url: "http://survey.wrud.net/api/image/delete",
             type: "POST",
             data: {
                 id: id
             },
             dataType: "json",
             success: function(res) {
                 if (0 == res.response.code) {
                     console.log("success");
                 }
             }
         });
     },
     crawlImage: function(e) {
         console.log("crawl");
         $.post("http://survey.wrud.net/api/image/crawl", {}, function(res) {
             if (0 == res.response.code) {
                 console.log("success");
             }
         })
     }
 });

 var AppImage = new VImage({
     model: new MImage()
 });

 AppImage.refresh(1);
 $('.pagination').jqPagination({
     link_string: '/?page={page_number}',
     current_page: 1,
     max_page: 10,
     page_string: '当前第{current_page}页,共{max_page}页',
     paged: function(page) {
         AppImage.refresh(page);
     }
=======
 var MImage = Backbone.Model.extend({
     //CURD
     listImage: function(pagenum) {
         $.ajax({
             url: "http://survey.wrud.net/api/image/index/" + pagenum,
             type: "GET",
             dataType: "json",
             data: {
                 type: 'admin'
             },
             success: function(res) {
                 AppImage.render(res.data);
             }
         });

     }

 });

 var VImage = Backbone.View.extend({
     events: {
         "click .btn-tagadd": "addTag",
         "click .btn-tagdel": "delTag",
         "click .btn-publish": "publishImage",
         "click .btn-crawl": "crawlImage",
         "click .btn-delete": "deleteImage"
     },
     initialize: function(argument) {
         this.setElement($('body'));
         this.first = true;
     },
     render: function(data) {
         html = "";
         for (var i = 0, len = data.length; i < len; i++) {
             data[i];

             data[i].height = parseInt(data[i].height) * 196 / parseInt(data[i].width);
             data[i].width = 196;
             data[i].url = data[i].source;
             html += template.render("pinTpl", data[i]);
         };
         $("#imglist").html(html);
         /*
         $container = $("#imglist");
         var $newElems = $(html);
         $container.masonry('appended', $newElems, true);
         var $img = $(newElements).find('.showGirl').css({
             opacity: 0
         });
         var $default = $(newElements).find('.Pin_default');
         //在添加到masonry布局之前保证图片载入
         $newElems.imagesLoaded(function() {
             //现在可以显示所有的元素了
             $img.animate({
                 opacity: 1
             });
             $default.hide().remove(); 
         });
         pagenum++;
        
         if (this.first) {
             this.first = false;
             $("#imglist").masonry({
                 itemSelector: '.img'
             });
         } else {
             $("#imglist").masonry("reload");
         }*/
     },

     refresh: function(pagenum) {
         console.log(pagenum)
         this.model.listImage(pagenum);
     },

     addTag: function(e) {
         var tagname = prompt("标签", "请在这里输入");
         if (tagname != null && tagname != "") {
             var id = $(e.target).parents(".img").attr("data-id");
             console.log("你输入的是：" + tagname);
         } else {
             console.log("你什么也没有输入");
         }
     },

     delTag: function(e) {
         var id = $(e.target).parents(".img").attr("data-id");
         var tag_id = $(e.target).attr("data-id");
         console.log("delete tag");
     },

     publishImage: function(e) {
         var id = $(e.target).parents(".img").attr("data-id");
         $.ajax({
             url: "http://survey.wrud.net/api/image/publish",
             type: "POST",
             data: {
                 id: id
             },
             dataType: "json",
             success: function(res) {
                 if (0 == res.response.code) {
                     console.log("success");
                 }
             }
         });
     },

     deleteImage: function(e) {
         var id = $(e.target).parents(".img").attr("data-id");
         $.ajax({
             url: "http://survey.wrud.net/api/image/delete",
             type: "POST",
             data: {
                 id: id
             },
             dataType: "json",
             success: function(res) {
                 if (0 == res.response.code) {
                     console.log("success");
                 }
             }
         });
     },
     crawlImage: function(e) {
         console.log("crawl");
         $.post("http://survey.wrud.net/api/image/crawl", {}, function(res) {
             if (0 == res.response.code) {
                 console.log("success");
             }
         })
     }
 });

 var AppImage = new VImage({
     model: new MImage()
 });

 AppImage.refresh(1);
 $('.pagination').jqPagination({
     link_string: '/?page={page_number}',
     current_page: 1,
     max_page: 10,
     page_string: '当前第{current_page}页,共{max_page}页',
     paged: function(page) {
         AppImage.refresh(page);
     }
>>>>>>> dbf1003d36b6e2f26527630b415dd0e79c8f56f0
 });